<template>
    <h1 ref="myMsg">{{ message }}</h1>
    <h3 v-if="msg1">{{ msg1 }}</h3>
    <h3 v-if="msg2">{{ msg2 }}</h3>
    <h3 v-if="msg3">{{ msg3 }}</h3>
    <button @click="chageMsg">赋值操作</button>
</template>

<script>
export default {
  name: 'App',
  data(){
    return{
      message:'害害害',
      msg1:'',
      msg2:'',
      msg3:''
    }
  },
  methods:{
    chageMsg(){
        this.message = "你好换洗";
        //虚拟DOM和真实DOM是异步操作
        this.msg1 = this.$refs.myMsg.innerHTML;
        //通过渲染回调机制解决问题
        this.$nextTick(() =>{//渲染回调 = 虚拟DOM和真实DOM同步过后的回调
            this.msg2 = this.$refs.myMsg.innerHTML;
        })
        this.msg3 = this.$refs.myMsg.innerHTML;
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
</style>
